package com.fulihui.systemcore.dal.convertor;

import com.fulihui.systemcore.dal.dataobj.PropertiesDO;
import com.fulihui.systemcore.dto.PropertiesDTO;
import org.near.toolkit.common.DateUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Willard.Hu on 2016/3/5.
 */
public class PropConv {

    private static final String[] ignore = new String[]{"gmtCreate", "gmtModified"};

    public static PropertiesDO toDO(PropertiesDTO dto) {
        if (dto == null) {
            return null;
        }
        PropertiesDO record = new PropertiesDO();
        record.setId(dto.getId());
        record.setProdName(dto.getProdName());
        record.setEnvType(dto.getEnvType());
        record.setPropKey(dto.getKey());
        record.setPropValue(dto.getValue());
        return record;
    }

    public static PropertiesDTO toDTO(PropertiesDO propDO) {
        if (propDO == null) {
            return null;
        }
        PropertiesDTO dto = new PropertiesDTO();
        dto.setId(propDO.getId());
        dto.setProdName(propDO.getProdName());
        dto.setEnvType(propDO.getEnvType());
        dto.setKey(propDO.getPropKey());
        dto.setValue(propDO.getPropValue());
        dto.setGmtCreate(DateUtils.formatNewFormat(propDO.getGmtCreate()));
        dto.setGmtModified(DateUtils.formatNewFormat(propDO.getGmtModified()));
        return dto;
    }

    public static List<PropertiesDTO> toList(List<PropertiesDO> propDOs) {
        if (propDOs == null) {
            return null;
        }
        return propDOs.stream().map(PropConv::toDTO).collect(Collectors.toList());
    }

}
